<?php
namespace app\admin\validate;

use think\Validate;
use app\admin\model\FlowGroupUser as FlowGroupUserModel;

class FlowGroupUser extends Validate
{
    protected $rule = [
        'group_id' => 'require',
        'uid' => 'require|checkGroupUser'
    ];
    
    protected $message = [
        'group_id.require' => '流程组不能为空！',
        'uid.require' => '组人员不能为空！',
        'uid.checkGroupUser' => '组人员已存在！'
    ];
    
    public function checkGroupUser($value, $rule, $data) 
    {
        $where = [
            'uid' => $value,
            'group_id' => $data['group_id'],
            'isvalid' => 1
        ];
        if (isset($data['id'])) {
            $where['id'] = ['neq', $data['id']];
        }
        $lists = (new FlowGroupUserModel())->where($where)->find();
        
        return $lists ? false : true;
    }
}

